<?php

namespace app\storeapi\controller;

use app\storeapi\model\store\User as StoreUser;
use app\storeapi\model\store\Clerk as ClerkUser;

/**
 * 登录
 * Class User
 * @package app\api
 */
class Passport extends  Controller
{

    /**
     * 账号密码登录
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function login()
    {
        $param =  $this->postData();
        //1 商户 2代言人
        $identity = $param['identity'];
        if($identity==1){
            $model = new StoreUser;
        }else{
            $model = new ClerkUser;
        }
        $data = $model->login($param);

        if ($data) {
            return $this->renderSuccess($data,'登录成功');
        }
        return $this->renderError($model->getError() ?: '登录失败');

    }

    /**
     * 忘记密码
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function forgetPass()
    {
        $param =  $this->postData();

        //1 商户 2代言人
        $identity = $param['identity'];
        if($identity==1){
            $model = new StoreUser;
        }else{
            $model = new ClerkUser;
        }

        $data = $model->forgetPass($param);

        if ($data) {
            return $this->renderSuccess([],'密码重置成功');
        }
        return $this->renderError($model->getError() ?: '密码重置失败');

    }



}
